package action;

import global.BaseException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import util.ServletHelp;

/**
 * BaseAction类,所有业务Action都继承该类.
 * <p>
 * 创建日期：2010-07-01<br>
 * 创建人：Xiyt<br>
 * 修改日期：<br>
 * 修改人：<br>
 * 修改内容：<br>
 * 
 * @author Xiyt
 * @version 1.0
 */
public class BaseAction extends DispatchAction {
	public final ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		try{
			return super.execute(mapping,form,request,response);
		}catch(Exception e){
			// 输出日志
			Logger logger = Logger.getLogger(BaseAction.class);
			logger.warn(e.getLocalizedMessage(), e);
			String exceptionMsg = BaseException.getExceptionStackTrace(e);
			
			// 返回结果
			JSONObject res = new JSONObject();
			res.put("success", false);
			res.put("exceptionMsg", exceptionMsg);
			ServletHelp.outRequestForJson(request, response, res.toString());
		}
		return null;
	}
}
